/*
 * @Author: sonss
 * @Date: 2024-03-03 21:36:46
 * @LastEditTime: 2024-03-07 18:35:50
 * @FilePath: /tencent-meeting-sdk-golang/qqmeeting/response.go
 * @Description:
 */
package qqmeeting

import (
	"encoding/json"
)

func (meeting Meeting) handleResponse(respBody []byte, descriptor *MeetingRequestDescriptor) (any, error) {
	var response any
	var err error
	switch *descriptor {
	case RequestDescriptorMeetingCreate:
		var resp MeetingCreateResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorUserCreate,
		RequestDescriptorUserUpdate,
		RequestDescriptorUserDelete,
		RequestDescriptorMeetingCancelByID,
		RequestDescriptorMeetingDismissByID:
		// 返回的body为空
		return nil, nil
	case RequestDescriptorUserDetailQuery:
		var resp UserDetailQueryResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorUserList:
		var resp UserListResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorMeetingQueryByCode, RequestDescriptorMeetingQueryByID:
		var resp MeetingQueryResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorMeetingUpdateByID:
		var resp MeetingUpdateResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorMeetingQueryParticipantsByID:
		var resp MeetingQueryParticipantsResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorMeetingQueryUserMeetingList:
		var resp MeetingQueryUserMeetingListResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorMeetingCustomerShortUrl:
		var resp MeetingCustomerShortUrlResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorMeetingSignIn:
		var resp MeetingSignInResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorMeetingQuerySignInList:
		var resp MeetingQuerySignInListResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorMeetingQuerySignInEventList:
		var resp MeetingQuerySignInEventListResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorRealControlMeetingCoHosts,
		RequestDescriptorRealControlMeetingMutes:
		return nil, nil
	case RequestDescriptorMeetingQueryRealTimeParticipantsByID:
		var resp MeetingQueryRealTimeParticipantsResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorRecordAddressesQuery:
		var resp RecordAddressesQueryResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	case RequestDescriptorRecordsQuery:
		var resp RecordsQueryResponse
		err = json.Unmarshal(respBody, &resp)
		response = resp
	default:

		/*
			log.Println("undefined response")
			log.Println(string(respBody))
			return nil, errors.New("undefined response")
		*/
		response = respBody
	}

	if err != nil {
		return nil, err
	} else {
		return response, nil
	}
}
